<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
</body>
<script>

    String.prototype.mysubstring=function(beginIndex,endIndex){
        var str=this,
            newArr=[];
        if(!endIndex){
            endIndex=str.length;
        }
        for(var i=beginIndex;i<endIndex;i++){
            newArr.push(str.charAt(i));
        }
        return newArr.join("");
    }

    //test
    console.log("Hello world!".mysubstring(3));
    console.log("Hello world!".mysubstring(3,7));

    //求字符串所有子串
    function subString(str) {
        for (var x = 0; x < str.length; x++) {
            for (var y = 0 ,z=str.length-x; z!==str.length+1; y++,z++) {
                var temp = str.substring(y,z);
                document.writeln(temp);
            }
        }
    }
    subString("wyz");
</script>
</html>